package com.ng.common.log.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ng.common.log.entity.WebsiteEntity;
import com.ng.common.log.service.impl.WebsiteService;
import com.ng.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author cb
 * @Description TODO
 * @date 2024/1/21
 */
@RestController
@RequestMapping("/webSite")
public class WebSiteController {
    @Autowired
    private WebsiteService websiteService;

    @PostMapping("/webSiteLog")
    public R<Object> webSiteLog(@RequestBody WebsiteEntity websiteEntity, HttpServletRequest request) {
        Map map = websiteService.webSiteLog(request, websiteEntity);

        return R.ok().setData(map);
    }

    /**
     * 数量统计
     * @param
     * @param
     * @param
     * @return
     */
    @GetMapping("/numStatistics")
    public R<Object> numStatistics() {
        List<Map> map = websiteService.numStatistics();

        return R.ok().setData(map);
    }

    @GetMapping("/getpv")
    public R<Object> getpv() {
        QueryWrapper<WebsiteEntity> queryWrapper=new QueryWrapper<WebsiteEntity>();
        int map = websiteService.count(queryWrapper.eq("type","pv"));
        return R.ok().setData(map);
    }

    /**
     * 查找今日,昨日浏览量总数
     * @param
     * @param
     * @param
     * @return
     */
    @GetMapping("/findWebSiteByDate")
    public R<Object> getWebSiteNum(@RequestParam String date) {
        List<Map> maps = websiteService.getWebSiteNumByDateAndType(date);
        return R.ok().setData(maps);
    }

    /**
     * 趋势图报表
     * @param date
     * @return
     */
    @GetMapping("/reportForm")
    public R<Object> reportForm(@RequestParam String date) {
//        Map maps = websiteService.reportForm(fromDate,toDate);
        Map maps =   websiteService.getReportFormByDate(date);
        return R.ok().setData(maps);
    }

    @GetMapping("/top10SearchWord")
    public  R<Object> top10SearchWord(){

        List<Map> maps = websiteService.top10SearchWord();

        return R.ok().setData(maps);
    }


}
